package com.heima.article.controller.v1;

import com.heima.article.service.ArticleHomeService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.ArticleConstants;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DiXiaoNie
 * @since 2022/12/19 10:40
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {

    @Autowired
    private ArticleHomeService articleHomeService;

    /**
     * 加载
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/22
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {

        return this.articleHomeService.loadV2(dto);
    }

    /**
     * 下拉
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/22
     */
    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto) {

        return this.articleHomeService.load(dto, ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    /**
     * 上拉
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/22
     */
    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto) {

        return this.articleHomeService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 保存
     *
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/22
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ArticleDto dto) {
        return this.articleHomeService.save(dto);
    }
}
